-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add std.valgrind module #1863
Add std.valgrind module #1863
Conversation
0f2e3f4
to
8ba418e
Compare
//pub fn printf(format: [*]const u8, args: ...) usize { | ||
// return doClientRequestExpr(0, | ||
// ClientRequest.PrintfValistByRef, | ||
// @ptrToInt(format), @ptrToInt(args), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocked on #515
//} | ||
|
||
|
||
pub fn nonSIMDCall0(func: fn(usize) usize) usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if I should make this into a vararg function
|
||
|
||
// Load PDB debug info for Wine PE image_map. | ||
// pub fn loadPdbDebuginfo(fd, ptr, total_size, delta) void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea how this function is meant to work or what the args are; it is underdocumented.
What kind of testing have you done with this so far? Here's what I see as the path forward on this, in roughly this order:
|
\\ xchgl %%ebx,%%ebx | ||
: [_] "={edx}" (-> usize) | ||
: [_] "{eax}" ([]usize{request, a1, a2, a3, a4, a5}), | ||
[_] "0" (default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constraint code appears to be undocumented. What are you expecting it to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a description on https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html#Simple-Constraints
An operand that matches the specified operand number is allowed. If a digit is used together with letters within the same alternative, the digit should come last.
This number is allowed to be more than a single digit. If multiple digits are encountered consecutively, they are interpreted as a single decimal integer. There is scant chance for ambiguity, since to-date it has never been desirable that ‘10’ be interpreted as matching either operand 1 or operand 0. Should this be desired, one can use multiple alternatives instead.
This is called a matching constraint and what it really means is that the assembler has only a single operand that fills two roles which asm distinguishes. For example, an add instruction uses two input operands and an output operand, but on most CISC machines an add instruction really has only two operands, one of them an input-output operand:
addl #35,r12
Matching constraints are used in these circumstances. More precisely, the two operands that match must include one input-only operand and one output-only operand. Moreover, the digit must be a smaller number than the number of the operand that uses it in the constraint.
I want to double check with LLVM that this is officially supported before depending on it. If not Zig should emit a compile error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is ready to merge yet. Aside from not passing CI tests, I double checked valgrind.h and the assembly you copied here is marked as being for
- amd64-{linux,darwin,solaris}
- x86-{linux,darwin,solaris}
Windows has different inline assembly.
I tried the code and it gave an invalid LLVM module error:
Call parameter type does not match function signature!
%7 = alloca [6 x i64], align 8
[6 x i64] %21 = call i64 asm sideeffect " rolq $$3, %rdi ; rolq $$13, %rdi\0A rolq $$61, %rdi ; rolq $$51, %rdi\0A xchgq %rbx,%rbx", "={rdx},{rax},0,~{cc},~{memory}"([6 x i64]* %7, i64 %20), !dbg !191
LLVM ERROR: Broken module found, compilation aborted!
As @Sahnvour notes, you can't pass an array directly to inline assembly. It's a bug in zig that it isn't a compile error.
It didn't seem to when I looked, it just doesn't take that code path in msvc due to using GCC inline assembly?
That must be new, I ran+tested the code in this PR.
Will fix.
Is there an issue open for that? |
There's #215 which is broader in scope. Actually from my experience and what @andrewrk told me about it, inline asm has enough support for basic stuff (namely doing syscalls) but that's about it. When you deviate a bit from simple uses, be sure to check with a debug build of Zig to trigger LLVM asserts. |
5261c6f
to
7387104
Compare
One quick test you can do to show this is working is: valgrindtest.zig: const std = @import("std");
const valgrind = std.valgrind; // @import("./std/valgrind/index.zig");
pub fn main() void {
std.debug.warn("{}\n", valgrind.runningOnValgrind());
}
|
7387104
to
5b75750
Compare
5b75750
to
1d78bb0
Compare
1d78bb0
to
7bbccfc
Compare
For #1837